package com.hsy.crm.web.web.basics;

import com.hsy.crm.web.domain.cm.App;
import com.hsy.crm.web.domain.cm.Response;
import com.hsy.crm.web.domain.cm.Unified;
import com.hsy.crm.web.domain.entity.Unit;
import com.hsy.crm.web.domain.vo.unit.UnitPageVo;
import com.hsy.crm.web.service.impl.UnitService;
import com.hsy.crm.web.web.BaseAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/unit")
public class UnitAction extends BaseAction {

    @Autowired
    UnitService unitService;

    @RequestMapping("/insert")
    public String insert(Unit unit) {
        unit.setType(App.UnitType.MASTER);
        return Response.body(Unified.newInstance(unitService.insert(unit,Boolean.TRUE)));
    }

    @RequestMapping("/update")
    public String update(Unit unit) {
        return Response.body(Unified.newInstance(unitService.update(unit,Boolean.TRUE)));
    }

    @RequestMapping("/delete")
    public String delete(Unit unit) {
        return Response.body(unitService.deleteUnit(unit));
    }

    @RequestMapping("/select")
    public String select(Unit unit) {
        unit.setType(App.UnitType.MASTER);
        return Response.body(Unified.newInstance(unitService.select(unit)));
    }

    @RequestMapping("/get")
    public String get(Unit unit) {
        return Response.body(Unified.newInstance(unitService.selectOne(unit)));
    }

    @RequestMapping("/page")
    public String page(UnitPageVo unitPageVo) {
        return Response.body(unitService.page(unitPageVo));
    }

}
